package com.sjf.day02.AnnoTest;

import java.lang.reflect.Field;

/**
 * 注解处理器
 */
public class FruitInfoUtil {
    public static void main(String[] args) {
        getFruitInfo(Apple.class);
    }
    public static void getFruitInfo(Class<?> clazz){
        String strFruitName=" 水果名称：";
        String strFruitColor=" 水果颜色：";
        String strFruitProvicer="供应商信息：";

        Field[] fileds = clazz.getDeclaredFields();
        for (Field filed : fileds) {
            if(filed.isAnnotationPresent(FruitName.class)){
                FruitName name = filed.getAnnotation(FruitName.class);
                System.out.println(strFruitName+name.value());
            }else if(filed.isAnnotationPresent(FruitColor.class)){
                FruitColor color = filed.getAnnotation(FruitColor.class);
                System.out.println(strFruitColor+color.fruitColor());
            }else if(filed.isAnnotationPresent(FruitProvider.class)){
                FruitProvider provider = filed.getAnnotation(FruitProvider.class);
                System.out.println(strFruitProvicer+"编号:"+provider.id()+"\t 名称："+provider.name()+"\t 地址："+
                        provider.address());
            }
        }
    }
}
